#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int n, m;
int main()
{
    cin >> n >> m;
    int totalnode = pow(2, n);
    while (m--)
    {
        string ret;
        cin >> ret;
        int left = 1, right = totalnode;
        for (auto &ch : ret)
        {
            int mid = (left + right) / 2;
            if (ch == 'y')
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }
        cout << left << endl;
    }
    return 0;
}